package it.patterns.structural.composite;

/**
 * 
 * Compose objects into tree structures to represent part-whole hierarchies.
 * Composite lets clients treat individual objects and compositions of objects
 * uniformly.
 * 
 * Clients use the Component class to interact with objects in the composite
 * structure. If the recipients is a leaf, then the request is handled directly.
 * If the recipient is a Component then it usually forwards requests to its
 * child components, possibly performing additional operations before and/or
 * after forwarding.
 * 
 * Additional implementations:
 * <ul>
 * <li>Maintain parent reference explicitly</li>
 * <li>Sharing components between more parents</li>
 * <li>Add to the component interface as many common operations for Composite
 * and Leaf possible</li>
 * <li>Declaring child management operations</li>
 * <li>Child ordering</li>
 * <li>Caching to improve performance</li>
 * <li>Make a composite responsible for delete its children</li>
 * <li>Other kind of data structures to store children</li>
 * </ul>
 * 
 * <img src="Composite.jpg" alt="Pattern Structure"/>
 * 
 * 
 * @author Luca D'Onofrio
 * 
 * @category Structural Pattern
 * @see "Design Patterns - Element of Reusable Object Oriented Software (Gamma,Helm, Johnson, Vlissides)"
 * 
 * @version 1.0
 */
public abstract class Composite {
	protected String name;

	public abstract String operation();

	public Composite(String name) {
		super();
		this.name = name;
	}

	public void add(Composite composite) throws Exception {
		if (composite instanceof Leaf)
			throw new Exception("Can not add on leaf.");

	}

	public void remove(Composite composite) throws Exception {
		if (composite instanceof Leaf)
			throw new Exception("Can not add on leaf.");
	}

	public void getChild() throws Exception {
	}
}
